package test;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 */
public class Future {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask1 = new FutureTask<String>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(5000);
                return "123";
            }
        });

        Thread thread = new Thread(futureTask1);
        thread.start();

        FutureTask<String> futureTask2 = new FutureTask<String>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(10000);
                return "456";
            }
        });

        Thread thread2 = new Thread(futureTask2);
        thread2.start();

        System.out.println(futureTask2.get());
        System.out.println(futureTask1.get());

        //just for test
    }

}
